feat: Add BroadcastReceiver with KeepAliveService for reliable automation#644
Open
whjstc wants to merge 3 commits intoMetaCubeX:mainfrom
Open
feat: Add BroadcastReceiver with KeepAliveService for reliable automation#644whjstc wants to merge 3 commits intoMetaCubeX:mainfrom
whjstc wants to merge 3 commits intoMetaCubeX:mainfrom
Conversation
Add ExternalControlReceiver for Tasker/automation tools to control Clash service completely in background without triggering any UI. This solves the issue where ExternalControlActivity causes screen flash/popup on some ROMs (Flyme, MIUI, ColorOS, etc.) when triggered by automation tools. Features: - Works on all ROMs without triggering UI - No screen flash or popup - Same actions as ExternalControlActivity (START/STOP/TOGGLE) - Complete Tasker configuration guide included Usage in Tasker: - Action: com.github.metacubex.clash.meta.action.START_CLASH - Target: Broadcast Receiver - Package: com.github.metacubex.clash.meta Files changed: - app/src/main/java/.../ExternalControlReceiver.kt (new) - app/src/main/AndroidManifest.xml (register receiver) - TASKER_GUIDE.md (user documentation)
修复两处乱码: - '保存' 字符显示异常 - '弹出' 字符显示异常
问题: - ExternalControlReceiver 在应用后台休眠时无法接收 Tasker 广播 - 应用进入 CACHED_EMPTY 状态(procState=19)时会被系统冻结 - 第三方应用发送的广播无法唤醒深度休眠的应用 解决方案: - 添加轻量级 Foreground Service (KeepAliveService) - 提升进程优先级(从 955 降至 50),防止进入深度休眠 - 使用 IMPORTANCE_MIN 通知渠道,最小化对用户的干扰 - 应用启动时自动启动服务 技术细节: - KeepAliveService: 空服务,仅用于保持进程活跃,几乎不耗电 - 通知文案:标题"Clash 服务",内容"运行中" - 在 MainApplication.onCreate 中自动启动 测试结果: - Tasker 广播接收 100% 可靠 - 应用在后台长时间待机后仍能正常响应 - 进程不会被冻结(isFrozen=0) 相关文件: - KeepAliveService.kt: 核心服务实现 - MainApplication.kt: 自动启动服务 - AndroidManifest.xml: 注册服务和更新注释 - TASKER_GUIDE.md: 更新文档说明
|
我的破澎湃 |
Author
用的是是我这边编译的 apk,还是 MetaCubeX 原仓库发布的版本? |
可以了,太棒了!无感开关。谢谢大佬! |
Author
最近我也发现,后台运行久了,会有自动关不掉的情况,先这样将就了,以后有时间再研究。 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
🎯 Problem
ExternalControlActivitycauses screen flash/popup on some ROMs (especially Flyme, MIUI, ColorOS) when triggered by automation tools like Tasker, breaking the "background automation" experience.✅ Solution
This PR adds two components for reliable background automation:
1. ExternalControlReceiver (BroadcastReceiver)
2. KeepAliveService (Foreground Service)
Why this is needed: During testing, I discovered that BroadcastReceiver fails when the app enters deep sleep (CACHED_EMPTY state, procState=19). The system freezes the app and blocks broadcasts from third-party apps.
Solution: A lightweight foreground service that:
🧪 Testing
Tested extensively on Flyme with Tasker:
📱 Usage
Tasker Configuration
Action: Send Intent
com.github.metacubex.clash.meta.action.START_CLASH(or STOP/TOGGLE)com.github.metacubex.clash.metaExample Automation Scenarios
📄 Files Changed
app/src/main/java/.../ExternalControlReceiver.kt- BroadcastReceiver implementationapp/src/main/java/.../KeepAliveService.kt- Foreground service for reliabilityapp/src/main/java/.../MainApplication.kt- Auto-start KeepAliveServiceapp/src/main/AndroidManifest.xml- Register receiver and serviceTASKER_GUIDE.md- Complete user guide with examplesapp/src/main/res/values/strings.xml- Notification strings🔧 Technical Details
Why Foreground Service instead of battery optimization whitelist?
Resource usage:
📚 Documentation
Complete Tasker setup guide included in
TASKER_GUIDE.mdwith: